package org.adw.launcher2.ld.secret.dom;

import java.io.ByteArrayOutputStream;

import org.adw.launcher2.ld.secret.db.MyVideoCache;
import org.adw.launcher2.ld.secret.ui.utils.Global;

import android.content.ContentValues;
import android.graphics.Bitmap;
import android.util.Log;


public class MyVideo  {
	private long id;
	private String absolutePathNoExtend;
	private String fileExtend;
	public Bitmap image;

	public void hide() {
		MyVideoCache cache = MyVideoCache.getInstance(Global.dbHelper);

		ContentValues values = new ContentValues();
		values.put("id", this.id);
		if(this.image!=null){
//			Log.d("MyVideo","image is != null, so put it in db by reading byte");
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
			image.compress(Bitmap.CompressFormat.PNG, 100, stream);
			byte[] byteArray = stream.toByteArray();
			values.put("image", byteArray );
		}else{
			Log.d("MyVideo","image is == null FUCK YOU ALL");
		}
		values.put("absolute_path_no_extend", this.absolutePathNoExtend);
		values.put("extend", this.fileExtend);
		cache.insertVideoToDb(values );
//		Log.d("Insert to db", id + "  " + absolutePathNoExtend + "  "  + fileExtend  );
		cache.deleteVideoFromMemory(this.id, this.image, this.absolutePathNoExtend, this.fileExtend);

	}


	public void restore() {
		MyVideoCache cache = MyVideoCache.getInstance(Global.dbHelper);
		Log.d("Insert to memory", id + "  " + absolutePathNoExtend + "  "  + fileExtend  );
		cache.insertVideoToMemory(new MyVideo(this.id, this.image,this.absolutePathNoExtend, this.fileExtend));
		cache.deleteVideoFromDb(id);
		
	}
	public MyVideo(long id, Bitmap image,String absolutePathNoExtend, String fileExtend){
		this.id = id;
		this.absolutePathNoExtend = absolutePathNoExtend;
		this.fileExtend = fileExtend;
		this.image = image;
	}
	public String getAbsolutePathNoExtend(){
		return this.absolutePathNoExtend;
	}
	public String getFileExtend(){
		return this.fileExtend;
	}
	public long getId(){
		return this.id;
	}
	public Bitmap getImage(){
		return this.image;
	}

}
